package builder.chained;

// 目标产品类
class Meal {
    private String burger;
    private String fries;
    private String drink;

    // 私有构造方法，强制使用 Builder
    private Meal() {
    }

    // 静态内部类 - 采用链式调用的建造者
    public static class Builder {
        private final Meal meal;

        public Builder() {
            meal = new Meal();
        }

        public Builder setBurger(String burger) {
            meal.burger = burger;
            return this;  // 返回 Builder 自己，实现链式调用
        }

        public Builder setFries(String fries) {
            meal.fries = fries;
            return this;
        }

        public Builder setDrink(String drink) {
            meal.drink = drink;
            return this;
        }

        public Meal build() {
            return meal;
        }
    }

    @Override
    public String toString() {
        return "Meal{burger='" + burger + "', fries='" + fries + "', drink='" + drink + "'}";
    }
}

public class BuilderTest {
    public static void main(String[] args) {
        // 构建牛肉套餐
        Meal beefMeal = new Meal.Builder()
                .setBurger("牛肉汉堡")
                .setFries("大份薯条")
                .setDrink("中杯可乐")
                .build();
        System.out.println("牛肉套餐：" + beefMeal);

        // 构建鸡肉套餐
        Meal chickenMeal = new Meal.Builder()
                .setBurger("鸡肉汉堡")
                .setFries("中份薯条")
                .setDrink("大杯果汁")
                .build();
        System.out.println("鸡肉套餐：" + chickenMeal);
    }
}